public class numberCompute {
    public static void main(String[] args) {
        int[][] cases = {
                {1, -2, 3, 5, -1},
                {1, -2, 3, -8, 5, 1},
                {1, -2, 3, -2, 5, 1}
        };

        // 输出每个案例的结果
        for (int[] arr : cases) {
            System.out.println(maxSubarraySum(arr));
        }
    }

    // 计算子数组最大和的核心方法
    private static int maxSubarraySum(int[] arr) {
        int current = arr[0], max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            current = Math.max(arr[i], current + arr[i]);
            max = Math.max(max, current);
        }
        return max;
    }
}

    